#include <stdio.h>
int main(){
	int i,n,t;
	scanf("%d",&n);
	int a[n];int b[n];
	for(i = 0;i<n;i++){
		scanf("%d",&a[i]);
	}for(i = 0;i<n;i++){
		b[i] = i;
	}t = 0;
	for(i = 1;i<n;i++){
		if(a[b[i]]<a[b[t]]){
			t = i;
		}
	}b[0] = b[t];b[t] = 0;
	t = n-1;
	for(i = 1;i<n-1;i++){
		if(a[b[i]]>a[b[t]]){
			t = i;                                                           
		}
	}b[n-1] = b[t];b[t] = n-1b;
	for(i = 0;i<n;i++){
		printf("%d",a[b[i]]);printf(" ");
	}return 0;	
}
